package com.xnyzc.lhy.order.mq;

import com.alibaba.fastjson.JSON;
import lombok.extern.slf4j.Slf4j;
import org.apache.rocketmq.client.producer.DefaultMQProducer;
import org.apache.rocketmq.client.producer.SendResult;
import org.apache.rocketmq.common.message.Message;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Component;
/**
 * @Author: huxuekuo
 * @Date: 2019-07-18 14:50
 * @Description:
 */
@Slf4j
@Component
public class MqDispatchLogProducer {


    /**
     * 生产者
     */
    @Autowired
    private DefaultMQProducer defaultMQProducer;

    /**
     * 给滴滴同步(做数据同步的发送)
     */
    public void sendMsg(Object param, String tags) {
        log.info("进入发送消息方法(Start)");
        String jsonString = JSON.toJSONString(param);
        log.info(">>>>  当前发送的标签: {}", tags);
        Message message = new Message("LHY_EVENT", tags, jsonString.getBytes());
        try {
            SendResult send = defaultMQProducer.send(message);
            log.info("MQ发送消息 订单信息{},发送结果{},发送状态:{}", param, send, send.getSendStatus());
        } catch (Exception e) {
            log.error(e.getMessage());
        }
        log.info("发送消息结束(End)");
    }
}
